home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / Gadgets / TabbedPanel.cp < prev    next >
Encoding:
Text File  |  1998-09-06  |  12.2 KB  |  486 lines  |  [TEXT/CWIE]

  1. // TabbedPanel.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "GadgetsEngine.h"
  24. #include "GadgetsDoc.h"
  25.  
  26. #include "TabbedPanel.h"
  27.  
  28.  
  29. //----------
  30. void    TabbedPanel::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     TabbedPanel*        winObj = new TabbedPanel;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. TabbedPanel::TabbedPanel ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. TabbedPanel::~TabbedPanel ()
  50. {
  51. }
  52.  
  53. //----------
  54. GadgetsEngine*    TabbedPanel::GetEngine ()
  55. {
  56.     return (GadgetsEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    TabbedPanel::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_TabbedPanel, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((GadgetsDoc*)mDoc)->mTabbedPanelPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_TabbedPanel);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.     mBarsHandle = ::GetNewControl (CNTL_Bars, window);
  89.     SetWindowItemFont (mBarsHandle, wftb, 1);
  90.  
  91.  
  92.     mScrollBarsHandle = ::GetNewControl (CNTL_ScrollBars, window);
  93.     EmbedControl (mScrollBarsHandle, mBarsHandle);
  94.     SetWindowItemFont (mScrollBarsHandle, wftb, 2);
  95.  
  96.     mStandard2Handle = ::GetNewControl (CNTL_Standard2, window);
  97.     EmbedControl (mStandard2Handle, mScrollBarsHandle);
  98.     SetWindowItemFont (mStandard2Handle, wftb, 3);
  99.  
  100.     mGraphicHandle = ::GetNewControl (CNTL_Graphic, window);
  101.     EmbedControl (mGraphicHandle, mScrollBarsHandle);
  102.     SetWindowItemFont (mGraphicHandle, wftb, 4);
  103.  
  104.     mSliderHandle = ::GetNewControl (CNTL_Slider, window);
  105.     EmbedControl (mSliderHandle, mScrollBarsHandle);
  106.     SetWindowItemFont (mSliderHandle, wftb, 5);
  107.  
  108.     mTickMarksHandle = ::GetNewControl (CNTL_TickMarks, window);
  109.     EmbedControl (mTickMarksHandle, mScrollBarsHandle);
  110.     SetWindowItemFont (mTickMarksHandle, wftb, 6);
  111.  
  112.     mNonDirectionalHandle = ::GetNewControl (CNTL_NonDirectional, window);
  113.     EmbedControl (mNonDirectionalHandle, mScrollBarsHandle);
  114.     SetWindowItemFont (mNonDirectionalHandle, wftb, 7);
  115.  
  116.     mLittleArrowsHandle = ::GetNewControl (CNTL_LittleArrows, window);
  117.     EmbedControl (mLittleArrowsHandle, mScrollBarsHandle);
  118.     SetWindowItemFont (mLittleArrowsHandle, wftb, 8);
  119.  
  120.     mSpinnerHandle = ::GetNewControl (CNTL_Spinner, window);
  121.     EmbedControl (mSpinnerHandle, mScrollBarsHandle);
  122.     SetWindowItemFont (mSpinnerHandle, wftb, 9);
  123.  
  124.     mVolumeControlHandle = ::GetNewControl (CNTL_VolumeControl, window);
  125.     EmbedControl (mVolumeControlHandle, mScrollBarsHandle);
  126.     SetWindowItemFont (mVolumeControlHandle, wftb, 10);
  127.  
  128.     mJimSSliderHandle = ::GetNewControl (CNTL_JimSSlider, window);
  129.     EmbedControl (mJimSSliderHandle, mScrollBarsHandle);
  130.     SetWindowItemFont (mJimSSliderHandle, wftb, 11);
  131.  
  132.  
  133.     mProgressBarsHandle = ::GetNewControl (CNTL_ProgressBars, window);
  134.     EmbedControl (mProgressBarsHandle, mBarsHandle);
  135.     SetWindowItemFont (mProgressBarsHandle, wftb, 12);
  136.  
  137.     mStandard3Handle = ::GetNewControl (CNTL_Standard3, window);
  138.     EmbedControl (mStandard3Handle, mProgressBarsHandle);
  139.     SetWindowItemFont (mStandard3Handle, wftb, 13);
  140.  
  141.     mIndeterminateHandle = ::GetNewControl (CNTL_Indeterminate, window);
  142.     EmbedControl (mIndeterminateHandle, mProgressBarsHandle);
  143.     SetWindowItemFont (mIndeterminateHandle, wftb, 14);
  144.     SetIndeterminateState (mIndeterminateHandle, true);
  145.  
  146.     mChasingArrowsHandle = ::GetNewControl (CNTL_ChasingArrows, window);
  147.     EmbedControl (mChasingArrowsHandle, mProgressBarsHandle);
  148.     SetWindowItemFont (mChasingArrowsHandle, wftb, 15);
  149.  
  150.     mRectangleHandle = ::GetNewControl (CNTL_Rectangle, window);
  151.     EmbedControl (mRectangleHandle, mProgressBarsHandle);
  152.     SetWindowItemFont (mRectangleHandle, wftb, 16);
  153.  
  154.     mRoundRectHandle = ::GetNewControl (CNTL_RoundRect, window);
  155.     EmbedControl (mRoundRectHandle, mProgressBarsHandle);
  156.     SetWindowItemFont (mRoundRectHandle, wftb, 17);
  157.  
  158.     mBarberPoleHandle = ::GetNewControl (CNTL_BarberPole, window);
  159.     EmbedControl (mBarberPoleHandle, mProgressBarsHandle);
  160.     SetWindowItemFont (mBarberPoleHandle, wftb, 18);
  161.  
  162.     mRoundBarberHandle = ::GetNewControl (CNTL_RoundBarber, window);
  163.     EmbedControl (mRoundBarberHandle, mProgressBarsHandle);
  164.     SetWindowItemFont (mRoundBarberHandle, wftb, 19);
  165.  
  166.     AdvanceKeyboardFocus (window);
  167.  
  168.     ShowWindow (window);
  169. }
  170.  
  171. //----------
  172. void    TabbedPanel::Close ()
  173. {
  174.     mData->RemoveResponder (this);
  175.  
  176.     ((GadgetsDoc*)mDoc)->mTabbedPanelPtr = nil;
  177.     SetInfo (nil);
  178.     HideWindow (mWindow);
  179.     DisposeWindow (mWindow);
  180.  
  181.     delete this;
  182. }
  183.  
  184. //----------
  185. void    TabbedPanel::ConnectToData (
  186.     DDocData*        inData)
  187. {
  188.     mData = inData;
  189.     mData->AddResponder (this);
  190.  
  191.     SetControlValue (mBarsHandle, mData->GetBars ());
  192.     SetLayerGroupValue (mBarsHandle, GetControlValue (mBarsHandle));
  193.     SetControlValue (mStandard2Handle, mData->GetStandard2 ());
  194.     SetControlValue (mGraphicHandle, mData->GetGraphic ());
  195.     SetControlValue (mSliderHandle, mData->GetSlider ());
  196.     SetControlValue (mTickMarksHandle, mData->GetTickMarks ());
  197.     SetControlValue (mNonDirectionalHandle, mData->GetNonDirectional ());
  198.     SetControlValue (mLittleArrowsHandle, mData->GetLittleArrows ());
  199.     SetControlValue (mSpinnerHandle, mData->GetSpinner ());
  200.     SetControlValue (mVolumeControlHandle, mData->GetVolumeControl ());
  201.     SetControlValue (mJimSSliderHandle, mData->GetJimSSlider ());
  202.     SetControlValue (mStandard3Handle, mData->GetStandard3 ());
  203.     SetControlValue (mIndeterminateHandle, mData->GetIndeterminate ());
  204.     SetControlValue (mChasingArrowsHandle, mData->GetChasingArrows ());
  205.     SetControlValue (mRectangleHandle, mData->GetRectangle ());
  206.     SetControlValue (mRoundRectHandle, mData->GetRoundRect ());
  207.     SetControlValue (mBarberPoleHandle, mData->GetBarberPole ());
  208.     SetControlValue (mRoundBarberHandle, mData->GetRoundBarber ());
  209. }
  210.  
  211. //----------
  212. void    TabbedPanel::DataChanged (
  213.     long        inDataID)
  214. {
  215.     if (inDataID == idBars) {
  216.         SetControlValue (mBarsHandle, mData->GetBars ());
  217.         SetLayerGroupValue (mBarsHandle, mData->GetBars ());
  218.     }
  219.     if (inDataID == idStandard2) {
  220.         SetControlValue (mStandard2Handle, mData->GetStandard2 ());
  221.     }
  222.     if (inDataID == idGraphic) {
  223.         SetControlValue (mGraphicHandle, mData->GetGraphic ());
  224.     }
  225.     if (inDataID == idSlider) {
  226.         SetControlValue (mSliderHandle, mData->GetSlider ());
  227.     }
  228.     if (inDataID == idTickMarks) {
  229.         SetControlValue (mTickMarksHandle, mData->GetTickMarks ());
  230.     }
  231.     if (inDataID == idNonDirectional) {
  232.         SetControlValue (mNonDirectionalHandle, mData->GetNonDirectional ());
  233.     }
  234.     if (inDataID == idLittleArrows) {
  235.         SetControlValue (mLittleArrowsHandle, mData->GetLittleArrows ());
  236.     }
  237.     if (inDataID == idSpinner) {
  238.         SetControlValue (mSpinnerHandle, mData->GetSpinner ());
  239.     }
  240.     if (inDataID == idVolumeControl) {
  241.         SetControlValue (mVolumeControlHandle, mData->GetVolumeControl ());
  242.     }
  243.     if (inDataID == idJimSSlider) {
  244.         SetControlValue (mJimSSliderHandle, mData->GetJimSSlider ());
  245.     }
  246.     if (inDataID == idStandard3) {
  247.         SetControlValue (mStandard3Handle, mData->GetStandard3 ());
  248.     }
  249.     if (inDataID == idIndeterminate) {
  250.         SetControlValue (mIndeterminateHandle, mData->GetIndeterminate ());
  251.     }
  252.     if (inDataID == idChasingArrows) {
  253.         SetControlValue (mChasingArrowsHandle, mData->GetChasingArrows ());
  254.     }
  255.     if (inDataID == idRectangle) {
  256.         SetControlValue (mRectangleHandle, mData->GetRectangle ());
  257.     }
  258.     if (inDataID == idRoundRect) {
  259.         SetControlValue (mRoundRectHandle, mData->GetRoundRect ());
  260.     }
  261.     if (inDataID == idBarberPole) {
  262.         SetControlValue (mBarberPoleHandle, mData->GetBarberPole ());
  263.     }
  264.     if (inDataID == idRoundBarber) {
  265.         SetControlValue (mRoundBarberHandle, mData->GetRoundBarber ());
  266.     }
  267. }
  268.  
  269. //----------
  270. void    TabbedPanel::Control (
  271.     ControlHandle        whichControl,
  272.     short                whichPart,
  273.     Point                where)
  274. {
  275.     Rect            bounds;
  276.     short            newValue;
  277.  
  278.     ExitCurField ();
  279.  
  280.     if (whichControl == mBarsHandle) {
  281.         if (TrackClick (mBarsHandle, where) != 0) {
  282.             mData->SetBars (GetControlValue (mBarsHandle));
  283.         }
  284.     }
  285.     if (whichControl == mStandard2Handle) {
  286.         HandleControlClick (mStandard2Handle, where, curEvent.modifiers, nil);
  287.         mData->SetStandard2 (GetControlValue (mStandard2Handle));
  288.     }
  289.     if (whichControl == mGraphicHandle) {
  290.         HandleControlClick (mGraphicHandle, where, curEvent.modifiers, nil);
  291.         mData->SetGraphic (GetControlValue (mGraphicHandle));
  292.     }
  293.     if (whichControl == mSliderHandle) {
  294.         HandleControlClick (mSliderHandle, where, curEvent.modifiers, nil);
  295.         mData->SetSlider (GetControlValue (mSliderHandle));
  296.     }
  297.     if (whichControl == mTickMarksHandle) {
  298.         HandleControlClick (mTickMarksHandle, where, curEvent.modifiers, nil);
  299.         mData->SetTickMarks (GetControlValue (mTickMarksHandle));
  300.     }
  301.     if (whichControl == mNonDirectionalHandle) {
  302.         HandleControlClick (mNonDirectionalHandle, where, curEvent.modifiers, nil);
  303.         mData->SetNonDirectional (GetControlValue (mNonDirectionalHandle));
  304.     }
  305.     if (whichControl == mLittleArrowsHandle) {
  306.         HandleControlClick (mLittleArrowsHandle, where, curEvent.modifiers, nil);
  307.         mData->SetLittleArrows (GetControlValue (mLittleArrowsHandle));
  308.     }
  309.     if (whichControl == mSpinnerHandle) {
  310.         HandleControlClick (mSpinnerHandle, where, curEvent.modifiers, nil);
  311.         mData->SetSpinner (GetControlValue (mSpinnerHandle));
  312.     }
  313.     if (whichControl == mVolumeControlHandle) {
  314.         HandleControlClick (mVolumeControlHandle, where, curEvent.modifiers, nil);
  315.         mData->SetVolumeControl (GetControlValue (mVolumeControlHandle));
  316.     }
  317.     if (whichControl == mJimSSliderHandle) {
  318.         HandleControlClick (mJimSSliderHandle, where, curEvent.modifiers, nil);
  319.         mData->SetJimSSlider (GetControlValue (mJimSSliderHandle));
  320.     }
  321. }
  322.  
  323. //----------
  324. void    TabbedPanel::MouseIn (
  325.     Point        where,
  326.     short        modifiers)
  327. {
  328.     Rect        bounds;
  329.  
  330. }
  331.  
  332. //----------
  333. void    TabbedPanel::ExitCurField ()
  334. {
  335.     ControlHandle    focus;
  336.  
  337.     GetKeyboardFocus (mWindow, &focus);
  338.  
  339.     if (focus == nil) {
  340.         // nothing to exit
  341.  
  342.     }
  343. }
  344.  
  345. //----------
  346. void    TabbedPanel::TypeIn (
  347.     char        ch)
  348. {
  349.     ControlHandle    focus;
  350.     SInt16            keyCode;
  351.  
  352.     GetKeyboardFocus (mWindow, &focus);
  353.  
  354.     if ((ch == charEnter)
  355.     ||  (ch == charReturn)) {
  356.         ExitCurField ();
  357.     } else if (ch == charEsc) {
  358.     } else if (ch == charTab) {
  359.         DoTab ((curEvent.modifiers & optionKey) != 0);
  360.     } else if (focus != nil) {
  361.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  362.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  363.         mDoc->mEngine->SetDirty ();
  364.     } else {
  365.         SysBeep (1);
  366.     }
  367. }
  368.  
  369. //----------
  370. void    TabbedPanel::Resize ()
  371. {
  372.     /* application-specific code to resize items in window */
  373. }
  374.  
  375. //----------
  376. void    TabbedPanel::Scroll (
  377.     short        newValue,
  378.     short        oldValue)
  379. {
  380.     /* application-specific code to scroll window */
  381.     if (gWhichScroll == vScroll) {
  382.     } else {    // horizontal
  383.     }
  384. }
  385.  
  386. //----------
  387. void    TabbedPanel::DoUndo ()
  388. {
  389. } // DoUndo
  390.  
  391. //----------
  392. void    TabbedPanel::DoCut ()
  393. {
  394.     TEHandle        curTE = GetCurTE ();
  395.  
  396.     if (curTE != nil) {
  397.         TECut (curTE);
  398.         mDoc->mEngine->SetDirty ();
  399.         scrapDirty = true;
  400.     }
  401. } // DoCut
  402.  
  403. //----------
  404. void    TabbedPanel::DoCopy ()
  405. {
  406.     TEHandle        curTE = GetCurTE ();
  407.  
  408.     if (curTE != nil) {
  409.         TECopy (curTE);
  410.         scrapDirty = true;
  411.     }
  412. } // DoCopy
  413.  
  414. //----------
  415. void    TabbedPanel::DoPaste ()
  416. {
  417.     TEHandle        curTE = GetCurTE ();
  418.  
  419.     if (curTE != nil) {
  420.         TEPaste (curTE);
  421.         mDoc->mEngine->SetDirty ();
  422.     }
  423. } // DoPaste
  424.  
  425. //----------
  426. void    TabbedPanel::DoClear ()
  427. {
  428.     TEHandle        curTE = GetCurTE ();
  429.  
  430.     if (curTE != nil) {
  431.         TEDelete (curTE);
  432.         mDoc->mEngine->SetDirty ();
  433.     }
  434. } // DoClear
  435.  
  436. //----------
  437. void    TabbedPanel::DoSelectAll ()
  438. {
  439.     TEHandle        curTE = GetCurTE ();
  440.  
  441.     if (curTE != nil) {
  442.         TESetSelect (0, 32767, curTE);
  443.     }
  444. } // DoSelectAll
  445.  
  446. //----------
  447. void    TabbedPanel::DoShowClipboard ()
  448. {
  449. } // DoShowClipboard
  450.  
  451. //----------
  452. Boolean        TabbedPanel::DoCommand (
  453.     long        inCommand)
  454. {
  455.     Boolean        result = true;
  456.  
  457.     switch (inCommand) {
  458.         case cmdUndo:
  459.                 DoUndo ();
  460.             break;
  461.         case cmdCut:
  462.                 DoCut ();
  463.             break;
  464.         case cmdCopy:
  465.                 DoCopy ();
  466.             break;
  467.         case cmdPaste:
  468.                 DoPaste ();
  469.             break;
  470.         case cmdClear:
  471.                 DoClear ();
  472.             break;
  473.         case cmdSelectAll:
  474.                 DoSelectAll ();
  475.             break;
  476.         case cmdShowClipboard:
  477.                 DoShowClipboard ();
  478.             break;
  479.  
  480.         default:
  481.                 result = false;
  482.     } // switch
  483.  
  484.     return result;
  485. }
  486.